package com.sitech.ibnms.c3p.util;

import com.sitech.dto.ResourceInfo;
import com.sitech.util.des.EncryptInterface;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一密码工具类
 * 调用CSD的云管理平台获取主机和数据库的密码
 */
public class SyscHostDbPasswdUtils {

    public static Map<String,String> SyscHostDbPasswd(String resTag) throws Exception {
        Map<String,String> passwdMap=new HashMap<String,String>();
        //先注释掉，到现场再放开注释
        try{
            ResourceInfo resourceInfo = EncryptInterface.desDecryptData(resTag);
            String code=resourceInfo.getRetCode();
            passwdMap.put("RES_TAG",resTag);
            //接口返回的数据都是解密的信息
            if("00".equals(code)){//调用成功
                //主机
                if(resourceInfo.getResType()==1){
                    passwdMap.put("HOST_IP",resourceInfo.getHostIP());
                    passwdMap.put("HOST_USER",resourceInfo.getHostUser());
                    passwdMap.put("HOST_PASSWD",resourceInfo.getHostPasswd());

                }else{//数据库
                    passwdMap.put("DB_SERVER",resourceInfo.getDbServ());//数据库标识
                    passwdMap.put("DB_URL",resourceInfo.getDbURL());
                    passwdMap.put("DB_USER",resourceInfo.getDbUser());
                    passwdMap.put("DB_PASSWD",resourceInfo.getDbPasswd());
                }
            }else{//调用失败
                System.out.println(resourceInfo.getRetDesc());
                throw new Exception(resourceInfo.getRetDesc());
            }
        }catch(Exception e){
            e.printStackTrace();
        }

        return passwdMap;
    }
}
